luci-mod-status: Cleanup and fix syslog.js bug
authorRamon Van Gorkom <[email protected]>
Fri, 27 Jun 2025 19:51:47 +0000 (21:51 +0200)
committerPaul Donald <[email protected]>
Sun, 29 Jun 2025 17:48:00 +0000 (19:48 +0200)
Fixed bug in syslog.js where lines could be hidden even when "any" was selected, and simplified code a bit.

Signed-off-by: Ramon Van Gorkom <[email protected]>
modules/luci-mod-status/htdocs/luci-static/resources/view/status/syslog.js

index 3c6f39184770b606ff09dc5f5bbf4dd3e0049c20..a71f4d95e71f29b83cce4aa1ef1c0cb5cb1b4db8 100644 (file)
@@ -8,12 +8,12 @@ return view.extend({
        logFacilityFilter: 'any',
        invertLogFacilitySearch: false,
        logSeverityFilter: 'any',
-       invertLogseveritySearch: false,
+       invertLogSeveritySearch: false,
        logTextFilter: '',
        invertLogTextSearch: false,
 
        facilities: [
-               ['any', '', _('Any')],
+               ['any', 'any', _('Any')],
                ['0',  'kern',   _('Kernel')],
                ['1',  'user',   _('User')],
                ['2',  'mail',   _('Mail')],
@@ -41,7 +41,7 @@ return view.extend({
        ],
 
        severity: [
-               ['any', '', _('Any')],
+               ['any','any', _('Any')],
                ['0',  'emerg',   _('Emergency')],
                ['1',  'alert',   _('Alert')],
                ['2',  'crit',   _('Critical')],
@@ -54,7 +54,6 @@ return view.extend({
 
 
        retrieveLog: async function() {
-               const facility = this.logFacilityFilter;
 
                return Promise.all([
                        L.resolveDefault(fs.stat('/usr/libexec/syslog-wrapper'), null),
@@ -64,24 +63,13 @@ return view.extend({
                        return fs.exec_direct(logger).then(logdata => {
                                let loglines = logdata.trim().split(/\n/);
 
-                               // Filter by facility, and additionally severity string if selected
-                               if (this.logSeverityFilter !== 'any') {
-                                       const sev = this.logSeverityFilter?.toLowerCase?.();
-                                       const fac = this.logFacilityFilter === 'any'
-                                               ? this.facilities.map(f => f[1]) // all facility short names
-                                               : [ this.facilities.find(f => f[0] === this.logFacilityFilter)?.[1] ];
-
-                                       loglines = loglines.filter(line => {
-                                               const sevMatch = this.logSeverityFilter === 'any' || fac.some(facility => line.includes(`.${sev}`));
-                                               const facMatch = this.logFacilityFilter === 'any' || fac.some(facility => line.includes(`${facility}.`));
-
-                                               const finalMatch = (this.invertLogseveritySearch ? !sevMatch : sevMatch)
-                                                              && (this.invertLogFacilitySearch ? !facMatch : facMatch);
-
-                                               return finalMatch;
-                                       });
+                               loglines = loglines.filter(line => {
+                                       const sevMatch = this.logSeverityFilter === 'any' || line.includes(`.${this.logSeverityFilter}`);
+                                       const facMatch = this.logFacilityFilter === 'any' || line.includes(`${this.logFacilityFilter}.`);
 
-                               }
+                                       return (this.invertLogSeveritySearch != sevMatch)
+                                                                  && (this.invertLogFacilitySearch != facMatch);
+                               });
 
                                loglines = loglines.filter(line => {
                                        const match = line.includes(this.logTextFilter);
@@ -122,14 +110,20 @@ return view.extend({
                                'class': 'cbi-button cbi-button-neutral'
                        }, _('Scroll to tail', 'scroll to bottom (the tail) of the log file')
                );
-               scrollDownButton.addEventListener('click', () => scrollUpButton.scrollIntoView());
+               scrollDownButton.addEventListener('click', () => {
+                       scrollUpButton.scrollIntoView();
+                       scrollDownButton.blur();
+               });
 
                const scrollUpButton = E('button', {
                                'id' : 'scrollUpButton',
                                'class': 'cbi-button cbi-button-neutral'
                        }, _('Scroll to head', 'scroll to top (the head) of the log file')
                );
-               scrollUpButton.addEventListener('click', () => scrollDownButton.scrollIntoView());
+               scrollUpButton.addEventListener('click', () => {
+                       scrollDownButton.scrollIntoView();
+                       scrollUpButton.blur();          
+               });
 
                const self = this;
 
@@ -146,13 +140,13 @@ return view.extend({
                        'class': 'cbi-input-select',
                        'style': 'margin-bottom:10px',
                },
-               this.facilities.map(([val, _, label]) =>
+               this.facilities.map(([_, val, label]) =>
                        E('option', { value: val }, label)
                ));
 
                // Create severity invert checkbox
                const severityInvert = E('input', {
-                       'id': 'invertLogseveritySearch',
+                       'id': 'invertLogSeveritySearch',
                        'type': 'checkbox',
                        'class': 'cbi-input-checkbox',
                });
@@ -183,16 +177,10 @@ return view.extend({
                        self.logFacilityFilter = facilitySelect.value;
                        self.invertLogFacilitySearch = facilityInvert.checked;
                        self.logSeverityFilter = severitySelect.value;
-                       self.invertLogseveritySearch = severityInvert.checked;
+                       self.invertLogSeveritySearch = severityInvert.checked;
                        self.logTextFilter = filterTextInput.value;
                        self.invertLogTextSearch = filterTextInvert.checked;
-                       self.retrieveLog().then(log => {
-                               const element = document.getElementById('syslog');
-                               if (element) {
-                                       element.value = log.value;
-                                       element.rows = log.rows;
-                               }
-                       });
+                       self.pollLog();
                }
 
                facilitySelect.addEventListener('change', handleLogFilterChange);
@@ -210,7 +198,7 @@ return view.extend({
                                        facilityInvert,
                                        E('label', { 'for': 'logFacilitySelect', 'style': 'margin: 0 5px' }, _('facility:')),
                                        facilitySelect,
-                                       E('label', { 'for': 'invertLogseveritySearch', 'style': 'margin: 0 5px' }, _('Not')),
+                                       E('label', { 'for': 'invertLogSeveritySearch', 'style': 'margin: 0 5px' }, _('Not')),
                                        severityInvert,
                                        E('label', { 'for': 'logSeveritySelect', 'style': 'margin: 0 5px' }, _('severity:')),
                                        severitySelect,